package com.maila.simplerecord.data;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;

import java.util.List;

/**
 * Created by Administrator on 2017/5/26.
 */
@Table(name = "Projectdata")
public class Projectdata extends Model {
    //项目id
    @Column(name = "pid")
    public int pid;
    //项目名称
    @Column(name = "project_name")
    public String project_name;
    //项目地址
    @Column(name = "address")
    public String address;
    //客户姓名
    @Column(name = "client_name")
    public String client_name;
    //客户电话
    @Column(name = "client_phone")
    public String client_phone;
    //开始时间
    @Column(name = "start_time")
    public String start_time;
    //结束时间
    @Column(name = "end_time")
    public String end_time;
    //图片路径
    @Column(name = "img_paths")
    public String img_paths;
    //明天计划
    @Column(name = "tomorrow_plan")
    public String tomorrow_plan;
    //备注
    @Column(name = "note")
    public String note;
    @Column(name = "top")
    public int top;
    @Column(name = "hide")
    public int hide=0;

    public int getTop() {
        return top;
    }

    public void setTop(int top) {
        this.top = top;
    }

    //单条查询
    public static Projectdata getRandom(int pid) {
        return new Select()
                .from(Projectdata.class)
                .where("pid = ?", pid)
                .orderBy("RANDOM()")
                .executeSingle();
    }

    //多条查询
    public static List<Projectdata> getAll() {
        return new Select()
                .from(Projectdata.class)
                .execute();
    }
    public static List<Projectdata> getAlled(int hide) {
        return new Select()
                .from(Projectdata.class)
                .and("hide = ?",hide)
                .execute();
    }
    //多条查询
    public static List<Projectdata> getAll(int top) {
        return new Select()
                .from(Projectdata.class)
                .where("top = ?", top)
                .and("hide = ?",0)
                .orderBy("id DESC")
                .execute();
    }

    public static int getcount() {
        if (new Select()
                .from(Projectdata.class)
                .where("hide = ?", 0)
                .execute()!=null){
            return new Select()
                    .from(Projectdata.class)
                    .where("hide = ?", 0)
                    .execute().size();
        }else{
            return 0;
        }

    }

    public static int getlastpid() {
        if (new Select()
                .from(Projectdata.class)
                .execute()!=null){
            List<Projectdata> datas=new Select()
                    .from(Projectdata.class)
                    .orderBy("pid ASC")
                    .execute();
            if(datas!=null&&datas.size()>1){
                return  datas.get(datas.size()-1).pid;
            }else {
                return 0;
            }

        }else{
            return 0;
        }

    }

    public static void deleteByID(int pid) {
        new Delete().from(Projectdata.class).where("pid = ?", pid).execute();
    }

    public static void clear() {
        new Delete().from(Projectdata.class).execute();
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getProject_name() {
        return project_name;
    }

    public void setProject_name(String project_name) {
        this.project_name = project_name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getClient_name() {
        return client_name;
    }

    public void setClient_name(String client_name) {
        this.client_name = client_name;
    }

    public String getClient_phone() {
        return client_phone;
    }

    public void setClient_phone(String client_phone) {
        this.client_phone = client_phone;
    }

    public String getStart_time() {
        return start_time;
    }

    public void setStart_time(String start_time) {
        this.start_time = start_time;
    }

    public String getEnd_time() {
        return end_time;
    }

    public void setEnd_time(String end_time) {
        this.end_time = end_time;
    }

    public String getImg_paths() {
        return img_paths;
    }

    public void setImg_paths(String img_paths) {
        this.img_paths = img_paths;
    }

    public String getTomorrow_plan() {
        return tomorrow_plan;
    }

    public void setTomorrow_plan(String tomorrow_plan) {
        this.tomorrow_plan = tomorrow_plan;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }
}
